#include "trap.h"
	.text
	#.align	2
	.globl	main
	.set	nomips16
	.set	nomicromips

main:

	.set	noreorder
	.set	nomacro
	addiu	$sp,$sp,-32
	sw	$31,28($sp)
	sw	$fp,24($sp)
	move	$fp,$sp
	li	$2,12			# 0xc
	sw	$2,16($fp)
	lw	$2,16($fp)
	move	$4,$2
	jal	get_lowbit
	nop

	sw	$2,20($fp)
	lw	$2,20($fp)
	#sltu	$2,$2,4
	bne	$2,$0,.L9
	nop

.L2:
	li	$2,15			# 0xf
	sw	$2,16($fp)
	lw	$3,16($fp)
	li	$2,-16			# 0xfffffffffffffff0
	or	$2,$3,$2
	sw	$2,16($fp)
	lw	$3,16($fp)
	li	$2,-1			# 0xffffffffffffffff
	bne	$3,$2,.L10
	nop

.L4:
	lw	$2,16($fp)
	sra	$2,$2,16
	sw	$2,16($fp)
	lw	$3,16($fp)
	li	$2,-1			# 0xffffffffffffffff
	bne	$3,$2,.L11
	nop

.L5:
	lw	$2,16($fp)
	srl	$2,$2,31
	sw	$2,16($fp)
	lw	$3,16($fp)
	li	$2,1			# 0x1
	bne	$3,$2,.L12
	nop

.L6:
	lw	$2,16($fp)
	sll	$2,$2,3
	addiu	$2,$2,-1
	sw	$2,16($fp)
	lw	$3,16($fp)
	li	$2,7			# 0x7
	bne	$3,$2,.L13
	nop

.L7:
	li	$2,2			# 0x2
	sw	$2,16($fp)
	li	$2,3			# 0x3
	sw	$2,20($fp)
	lw	$3,16($fp)
	lw	$2,20($fp)
	xor	$2,$3,$2
	sw	$2,16($fp)
	lw	$2,16($fp)
	lw	$3,20($fp)
	xor	$2,$3,$2
	sw	$2,20($fp)
	lw	$3,16($fp)
	lw	$2,20($fp)
	xor	$2,$3,$2
	sw	$2,16($fp)
	lw	$3,16($fp)
	li	$2,3			# 0x3
	bne	$3,$2,.L3
	nop

	lw	$3,20($fp)
	li	$2,2			# 0x2
	bne	$3,$2,.L3
	nop

	move	$2,$0
	#HIT_GOOD_TRAP
	b	.L8
	nop

.L9:
	nop
	b	.L3
	nop

.L10:
	nop
	b	.L3
	nop

.L11:
	nop
	b	.L3
	nop

.L12:
	nop
	b	.L3
	nop

.L13:
	nop
.L3:
	li	$2,-1			# 0xffffffffffffffff
.L8:
	move	$sp,$fp
	lw	$31,28($sp)
	lw	$fp,24($sp)
	addiu	$sp,$sp,32
	j	.L2
	nop



	#.align	2
	.globl	get_lowbit
	.set	nomips16
	.set	nomicromips
get_lowbit:

	.set	noreorder
	.set	nomacro
	addiu	$sp,$sp,-8
	sw	$fp,4($sp)
	move	$fp,$sp
	sw	$4,8($fp)
	lw	$2,8($fp)
	subu	$3,$0,$2
	lw	$2,8($fp)
	and	$2,$3,$2
	move	$sp,$fp
	lw	$fp,4($sp)
	addiu	$sp,$sp,8
	j	.L2
	nop
